﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;

<script>
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });

    //加载树
    var _pstructId = "";
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    var pstructName = "";
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 141.5);
                $("#itemTree").setTreeHeight($(window).height() - 55.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#PStructTree").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==请选择组织机构==",
            height: "250px",
            click: function (item) {
                _organizeid = item.id;
                _pstructId = "";
                GetTree();
                $('#btn_Search').trigger("click");
            }
        });

        $("#PStructTree").ComboBoxTreeSetValue(_organizeid);
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../ResourceManage/RS_PStructs/GetTreeNameJson?OrganizeId=" + _organizeid,
            onnodeclick: function (item) {
                if (item.id != _pstructId) {
                    _pstructId = item.id;
                    _organizeid = $("#PStructTree").attr("data-value");
                    $('#btn_Search').trigger("click");
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["OrganizeId"] = _organizeid;
        queryJson["PStructId"] = _pstructId;
      
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructUser/GetListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "id", index: "id", hidden: true },
                { label: "关联关系ID", name: "relationpcid", index: "relationpcid", hidden: true },
                { label: "客户编号", name: "code", index: "code", width: 150, align: "left", sortable: true },
                { label: "客户名称", name: "name", index: "name", width: 150, align: "left", sortable: true },
                 { label: "简称", name: "shortname", index: "shortname", width: 150, align: "left", sortable: true },
                {
                    label: "客户类型", name: "type", index: "type", width: 70, align: "center", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 2 ? "<span>租户</span>" : "<span>业主</span>";
                    }
                },
                { label: "房间ID", name: "pstructid", index: "pstructid", hidden: true },
                {
                    label: "所属房间", name: "pstructname", index: "pstructname", width: 150, align: "center", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        
                        return cellvalue==null||cellvalue == "" ? "<span class=\"label label-danger\">未绑定房间</sapn>" : cellvalue;
                    }
                },
                {
                    label: "入住类型", name: "flag", index: "flag", width: 70, align: "center", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<span>个人</span>" : "<span>公司</span>";
                    }
                },
                { label: "手机号码", name: "phonenum", index: "phonenum", width: 100, align: "left", sortable: true },
                {
                    label: "客户证件类型", name: "certificatetype", index: "certificatetype", width: 90, align: "center", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 2 ? "<span>护照</span>" :cellvalue == 1? "<span>身份证</span>":"";
                    }
                },
                { label: "客户证件编号", name: "certificateno", index: "certificateno", width: 100, align: "left", sortable: true },
                 { label: "备注", name: "memo", width: 200, align: "left", sortable: false }
            ],
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable:true,
            sortname: 'Code',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = $("#filter-form").GetWebControls();
            queryJson["PStructId"] = _pstructId;
            queryJson["OrganizeId"] = _organizeid;
            queryJson["Code"] =$("#queryCondition").find('.dropdown-text').attr('data-value')=="Code"?$("#txt_Keyword").val():"",
            queryJson["Name"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "Name" ? $("#txt_Keyword").val() : "",
            queryJson["CertificateNO"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "CertificateNO" ? $("#txt_Keyword").val() : "",
            queryJson["PhoneNum"] = $("#queryCondition").find('.dropdown-text').attr('data-value') == "PhoneNum" ? $("#txt_Keyword").val() : "",

            $gridTable.jqGrid('setGridParam', {
                postData: {  queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加客户资料',
            url: '/ResourceManage/RS_PStructUser/Form',
            width: "800px",
            height: "630px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        var PStructId = $("#gridTable").jqGridRowValue("pstructid");
        if (checkedRow(keyValue) ) {
            dialogOpen({
                id: "Form",
                title: '编辑客户资料',
                url: '/ResourceManage/RS_PStructUser/Form?keyValue=' + keyValue + '&pstructId=' + PStructId,
                width: "800px",
                height: "630px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //详情
    function btn_details() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        var PStructName = $("#gridTable").jqGridRowValue("pstructname");
        if (keyValue) {
            dialogOpen({
                id: "Form",
                title: '添加客户资料',
                url: '/ResourceManage/RS_PStructUser/Details?keyValue=' + keyValue + '&PStructName=' + encodeURI(encodeURI(PStructName)),
                width: "800px",
                height: "630px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_PStructUser/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    dialogMsg(errorThrown, 0);
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px;"><div id="PStructTree" type="selectTree" class="ui-select"></div></div>
            <div id="itemTree" style=" height: 320px; border-bottom: 1px dashed #cecece;"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编码</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                        <li><a data-value="CertificateNO">证件编号</a></li>
                                        <li><a data-value="PhoneNum">手机号码</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        @*<label id="lr-details" class="btn btn-default" onclick="btn_details()"><i class="fa fa-pencil-square-o"></i>&nbsp;详情</label>*@
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
    @*<div class="ui-layout-east">
            <div class="east-Panel">
                <div class="panel-Title">
                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#panel1" data-toggle="tab">资料卡片</a>
                        </li>
                    </ul>
                </div>
                <div class="tab-content">
                    <div class="tab-pane active" id="panel1">
                        <ul class="folder-list" style="border-bottom: 1px dashed #cecece; border-top: 1px dashed #cecece; ">
                            <li>
                                编号：<input type="text" />
                            </li>
                            <li>
                                名称：<input type="text" />
                            </li>
                            <li>
                                性质：<select style="width: 53%;"></select>
                            </li>
                            <li>
                                状态：<input type="text" />
                            </li>
                            <li>
                                业态：<input type="text" />
                            </li>
                            <li>
                                面积：<input type="text" />
                            </li>
                        </ul>
                        <h5 style=" padding: 10px; background: #edf1f2; ">备注说明</h5>
                        <textarea style="width:100%;height:60px;"></textarea>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>
                        <h5 style=" padding: 10px; background: #edf1f2; ">图档</h5>
                        <div style="border: 1px solid #cecece; height: 200px;">
                            <img />
                        </div>
                        <div class="hr-line-dashed" style="border-top: 1px dashed #e7eaec;    color: #ffffff;    background-color: #ffffff;    height: 1px;    margin: 10px 0;"></div>
                    </div>
                </div>
            </div>
        </div>*@
    <style>
        .folder-list li {
            padding: 10px 0 10px 5px;
            height: 40px;
        }

        .nav-tabs {
            padding-top: 1px;
        }
    </style>
</div>
